package com.mes.schedule.manager;

import java.util.concurrent.Callable;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.mes.schedule.domain.ScheduleScheme;


/**
 * 主要为了处理不同用户的调度方案问题 应对不同的用户
 * 
 * @author lh
 *
 */
public class ScheduleThread implements Callable<Boolean> {
	private final static Log log = LogFactory.getLog(ScheduleThread.class);

	protected ScheduleManager scheduleManager;

	protected ScheduleScheme scheme;
	protected int mode;

	public int getMode() {
		return mode;
	}

	public void setMode(int mode) {
		this.mode = mode;
	}

	public ScheduleThread(ScheduleManager scheduleManager, ScheduleScheme scheme, int mode) {
		super();
		this.scheduleManager = scheduleManager;
		this.scheme = scheme;

		this.mode = mode;
	}

	public Boolean call() {
		try {
			if (log.isDebugEnabled()) {
				Thread.currentThread().setName("调度主线程 " + scheme.getScheduleUid());
			}
			// 调度前处理
			log.info("开始执行多线程算法");
			scheduleManager.beforeSchedule(scheme, mode);
			// 调度处理
			System.out.println("1");
			scheduleManager.schedule(scheme, mode);
			// 调度后处理
			scheduleManager.afterSchedule(scheme, mode);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			return true;

		}

	}

	// 之前采用继承关系，现在实现接口试一下，SnowBear

}
